package com.kelvin.paopao.module.person.edit;

import com.hyphenate.easeui.utils.SpUtil;
import com.kelvin.paopao.PaoPaoApplication;
import com.kelvin.paopao.api.RetrofitService;
import com.kelvin.paopao.api.responseBean.CommonListResponse;
import com.kelvin.paopao.api.responseBean.PersonPhotoModel;
import com.kelvin.paopao.api.responseBean.TalkPriceModel;
import com.kelvin.paopao.api.responseBean.UserDetailModel;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administrator on 2017/5/14.
 */

public class PersonDetailEditPresenter implements IPersonDetailEditPresenter {

    private PersonDetailEditActivity mVIew;

    public PersonDetailEditPresenter(PersonDetailEditActivity view) {
        this.mVIew = view;
    }


    @Override
    public void updateInfo(String user_name, String user_age, String user_qianming, String user_zhiye,
                           String user_tizhong, String user_shengao, String user_province, String user_city,
                           String user_ganqing, String user_label) {
        RetrofitService.updateInfo(user_name, user_age, user_qianming,
                user_zhiye, user_tizhong, user_shengao,
                user_province, user_city, user_ganqing, user_label)
                .subscribe(new Consumer<CommonListResponse>() {
                    @Override
                    public void accept(@NonNull CommonListResponse commonListResponse) throws Exception {
                        if (commonListResponse.getReason().equals("成功")) {
                            mVIew.finish();
                        }
                    }
                });
    }

    @Override
    public void addPersonPhoto(String imgPath) {

    }

    @Override
    public void removePersonPhoto(String id) {

    }

    @Override
    public void getTalkMoney() {
        RetrofitService.getTalkMoney(SpUtil.getLoginHuanxin_id(mVIew)).subscribe(new Consumer<CommonListResponse<TalkPriceModel>>() {
            @Override
            public void accept(@NonNull CommonListResponse<TalkPriceModel> talkPriceModelCommonListResponse) throws Exception {
                if (talkPriceModelCommonListResponse.getResult() != null &&
                        talkPriceModelCommonListResponse.getResult().size() != 0) {
                    mVIew.updateTalkMoney(talkPriceModelCommonListResponse.getResult().get(0));
                }
            }
        });
    }

    @Override
    public void getPsPrice() {
        RetrofitService.getUserInfo(SpUtil.getLoginHuanxin_id(mVIew)).subscribe(new Consumer<CommonListResponse<UserDetailModel>>() {
            @Override
            public void accept(@NonNull CommonListResponse<UserDetailModel> userDetailModelCommonListResponse) throws Exception {
                if (userDetailModelCommonListResponse.getReason().equals("成功")) {
                    mVIew.loadData(userDetailModelCommonListResponse.getResult().get(0));
                }
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(@NonNull Throwable throwable) throws Exception {

            }
        }, new Action() {
            @Override
            public void run() throws Exception {

            }
        });
    }

    @Override
    public void getData(boolean isRefresh) {
        RetrofitService.getPersonPhoto().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<CommonListResponse<PersonPhotoModel>>() {
                    @Override
                    public void accept(@NonNull CommonListResponse commonListResponse) throws Exception {
                        mVIew.loadPersonPhoto(commonListResponse.getResult());
                    }
                });

        RetrofitService.getUserInfo(SpUtil.getLoginHuanxin_id(mVIew)).subscribe(new Consumer<CommonListResponse<UserDetailModel>>() {
            @Override
            public void accept(@NonNull CommonListResponse<UserDetailModel> userDetailModelCommonListResponse) throws Exception {
                if (userDetailModelCommonListResponse.getReason().equals("成功")) {
                    mVIew.loadData(userDetailModelCommonListResponse.getResult().get(0));
                }
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(@NonNull Throwable throwable) throws Exception {

            }
        }, new Action() {
            @Override
            public void run() throws Exception {

            }
        });
    }

    @Override
    public void getMoreData() {

    }
}
